package com.heima.controller;

import com.heima.common.result.PageResult;
import com.heima.common.result.Result;
import com.heima.pojo.dto.VmDTO;
import com.heima.pojo.entity.VendingMachine;
import com.heima.pojo.vo.NodeDetailVO;
import com.heima.service.VendingMachineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * \* User: chy
 * \* Date: 2025/8/22  14:06
 * \* Description:设备管理
 * \
 */
@RestController
@RequestMapping("/api/vm-service/vm")
@Slf4j
public class VendingMachineController {

    @Autowired
    private VendingMachineService vendingMachineService;

    /**
     * 设备搜索
     * @param vmDTO
     * @return
     */
    @GetMapping("search")
    public PageResult<NodeDetailVO> page(VmDTO vmDTO) {
        log.info("设备搜索{}", vmDTO);
        PageResult<NodeDetailVO> pageResult = vendingMachineService.pageResult(vmDTO);
        return pageResult;  //
    }

    /**
     * 新增设备
     * @param vendingMachine
     * @return
     */
    @PostMapping
    public Result add(@RequestBody VendingMachine vendingMachine) {
        log.info("新增设备{}", vendingMachine);
        boolean save = vendingMachineService.saveVm(vendingMachine);
            return Result.success(save);
    }
    /**
     * 修改设备
     * @param id
     * @param nodeId
     * @return
     */
    @PutMapping("/{id}/{nodeId}")
    public Result update(@PathVariable Long id,@PathVariable Long nodeId) {
        log.info("修改设备{} ,{}", id, nodeId);
        boolean update = vendingMachineService.updateVmNode(id,nodeId);
        return Result.success(update);
    }
}
